Core.Test.registerTest({
	group: "dao",
	name: "Core.Storage.PathResolver",
	envs: ["storage.simple"],
	
	before: function() {
		this.conf = new Core.Storage.Configuration();
		this.valuer = new Core.Storage.ValueResolver(this, this.conf);
		this.pathr = this.valuer.pathr;
	},
	
	override: function(property, value) {
		this.conf.override(property, value, this, 20);
	},
	
	"Should resolve plain global path": function() {
		var path = this.pathr.evaluate("..user.login.name");
		Assert.equal("..user.login.name", path);
	},
	
	"Should resolve braced global path": function() {
		var path = this.pathr.evaluate("..menu.items{ ..user.current.site }");
		Assert.equal("..menu.items.2", path);
	},
	
	"Should resolve plain accessor path": function() {
		var path = this.pathr.evaluate(".prop");
		Assert.equal(".prop", path);
	},
	
	"Should resolve braced accessor path (1)": function() {
		this.override("inx", 3);
		
		var path = this.pathr.evaluate(".arr{ .inx }");
		Assert.equal(".arr.3", path);
	},
	
	"Should resolve braced accessor path (2)": function() {
		this.override("inx", 3);
		
		var path = this.pathr.evaluate(".arr{ .inx }id");
		Assert.equal(".arr.3.id", path);
	},
	
	"Should resolve braced accessor path (3)": function() {
		this.override("inx", function() { return "property" });
		
		var path = this.pathr.evaluate(".object{ .inx }");
		Assert.equal(".object.property", path);
	},
	
	"Should resolve braced accessor path (4)": function() {
		this.override("inx", function() { return "{ .property }" });
		this.override("property", function() { return "12" });
		
		var path = this.pathr.evaluate(".object{ .inx }");
		Assert.equal(".object.12", path);
	},
	
	"Should resolve braced accessor path (5)": function() {
		this.override("one", "one");
		this.override("two", "two");
		
		var path = this.pathr.evaluate(".{ .one }{ .two }three");
		Assert.equal(".one.two.three", path);
	},
	
	"Should resolve indirect accessor path (1)": function() {
		this.override("indirect", "..user.login.name");
		
		var path = this.pathr.evaluate("{ .indirect }");
		Assert.equal("..user.login.name", path);
	},
	
	"Should resolve indirect accessor path (2)": function() {
		this.override("indirect", "..menu.items{ ..user.current.site }");
		
		var path = this.pathr.evaluate("{ .indirect }");
		Assert.equal("..menu.items.2", path);
	},
	
	"Should resolve indirect accessor path (3)": function() {
		debug = true;
		this.override("indirect", "..menu.items{ ..user.current.site }");
		
		var path = this.pathr.evaluate("{ .indirect }name");
		Assert.equal("..menu.items.2.name", path);
	},
	
	"Should resolve plain local path (global accessor)": function() {
		var	path = this.pathr.evaluate("..user.login/name"),
			uid = Core.uid(Core.Storage.get("user.login"));
				
		Assert.equal("..local." + uid + ".name", path);
	},
	
	"Should resolve plain local path (local accessor)": function() {
		this.override(".loops", {});
		
		var	path = this.pathr.evaluate(".loops/name"),
			uid = Core.uid(this.conf.get("loops"));
			
		Assert.equal("..local." + uid + ".name", path);
	},
	
	"Should resolve braced local path (1)": function() {
		this.override("prop", "items");
		
		var path = this.pathr.evaluate("..menu{ .prop }/name"),
			uid = Core.uid(Core.Storage.get("menu.items"));

		Assert.equal("..local." + uid + ".name", path);
	},
	
	"Should resolve braced local path (2)": function() {
		this.override("prop", "2");
		
		var path = this.pathr.evaluate("..menu.items/{ .prop }"),
			uid = Core.uid(Core.Storage.get("menu.items"));

		Assert.equal("..local." + uid + ".2", path);
	},
	
	"Should resolve local owner path": function() {
		var path = this.pathr.evaluate("./name"),
			uid = Env.stamp(this);
		
		Assert.equal("..local." + uid + ".name", path);
	}
});